﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CameraToggle
{
    class CameraMath
    {
        public static double ViewEdge(double viewEdge, double baseImgSide, double nextImgSide)
        {
            return viewEdge / baseImgSide * nextImgSide;
        }
        public static double ViewEdgeByPixel(double baseEdge,double pixelSize)
        {
            return baseEdge * pixelSize / 1000;
        }
        public static double ForcalLength(double viewHeight, double viewWidth, double viewLength,
           double imgWidth, double imgHeight,
           double pixelSizeX,double pixelSizeY)
        {
            double wights = ViewEdgeByPixel(imgWidth, pixelSizeX);
            double heights = ViewEdgeByPixel(imgHeight, pixelSizeY);
            return viewLength * wights / viewWidth;
        }

        public static double ViewAngle(double baseAngle, double baseLength, double nextLength)
        {
            double radian = Degree2Radian(baseAngle / 2.0);
            double tan = Math.Tan(radian) * baseLength / nextLength;
            double atan = Math.Atan(tan);
            return Radian2Degree(atan) * 2;
        }

        public static double ViewEdge(double viewLength,double angle)
        {
            return viewLength * (Math.Tan(Degree2Radian(angle / 2.0))) * 2;
        }
        public static double Degree2Radian(double degree)
        {
            return degree * Math.PI / 180.0;
        }
        public static double Radian2Degree(double radian)
        {
            return radian/ Math.PI* 180.0;
        }
    }
}
